﻿using Commen;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AyaWo.WinForm
{
    public partial class TonbuForm : Form
    {
        public TonbuForm()
        {
            InitializeComponent();
            var tty = DatHelper<int>.GetDatList("Tonbu.dat");
            SetValue(tty);
        }

        private void btn_Save_Click(object sender, EventArgs e)
        {
            try
            {
                DatHelper<int>.SaveDat("Tonbu.dat", fastJSON.JSON.Instance.ToJSON(GetValue()));
                MessageBox.Show("保存成功...");
            }
            catch
            {
                MessageBox.Show("保存失败...");
            }
        }

        List<int> GetValue()
        {
            List<int> li = new List<int>();
            if (cb_1.Checked == true) { li.Add(1); }
            if (cb_2.Checked == true) { li.Add(2); }
            if (cb_3.Checked == true) { li.Add(3); }
            if (cb_4.Checked == true) { li.Add(4); }
            if (cb_5.Checked == true) { li.Add(5); }
            if (cb_6.Checked == true) { li.Add(6); }
            if (cb_7.Checked == true) { li.Add(7); }
            if (cb_8.Checked == true) { li.Add(8); }
            if (cb_9.Checked == true) { li.Add(9); }
            if (cb_10.Checked == true) { li.Add(10); }
            if (cb_11.Checked == true) { li.Add(11); }
            if (cb_12.Checked == true) { li.Add(12); }
            if (cb_13.Checked == true) { li.Add(13); }
            if (cb_14.Checked == true) { li.Add(14); }
            if (cb_15.Checked == true) { li.Add(15); }
            if (cb_16.Checked == true) { li.Add(16); }
            if (cb_17.Checked == true) { li.Add(17); }
            if (cb_18.Checked == true) { li.Add(18); }
            if (cb_19.Checked == true) { li.Add(19); }
            if (cb_20.Checked == true) { li.Add(20); }
            if (cb_21.Checked == true) { li.Add(21); }
            if (cb_22.Checked == true) { li.Add(22); }
            if (cb_23.Checked == true) { li.Add(23); }
            if (cb_24.Checked == true) { li.Add(0); }
            return li;
        }

        void SetValue(List<int> li)
        {

            if (li == null || li.Count() < 0)
                return;
            foreach (var l in li)
            {
                if (l == 1) cb_1.Checked = true;
                else if (l == 2) cb_2.Checked = true;
                else if (l == 3) cb_3.Checked = true;
                else if (l == 4) cb_4.Checked = true;
                else if (l == 5) cb_5.Checked = true;
                else if (l == 6) cb_6.Checked = true;
                else if (l == 7) cb_7.Checked = true;
                else if (l == 8) cb_8.Checked = true;
                else if (l == 9) cb_9.Checked = true;
                else if (l == 10) cb_10.Checked = true;
                else if (l == 11) cb_11.Checked = true;
                else if (l == 12) cb_12.Checked = true;
                else if (l == 13) cb_13.Checked = true;
                else if (l == 14) cb_14.Checked = true;
                else if (l == 15) cb_15.Checked = true;
                else if (l == 16) cb_16.Checked = true;
                else if (l == 17) cb_17.Checked = true;
                else if (l == 18) cb_18.Checked = true;
                else if (l == 19) cb_19.Checked = true;
                else if (l == 20) cb_20.Checked = true;
                else if (l == 21) cb_21.Checked = true;
                else if (l == 22) cb_22.Checked = true;
                else if (l == 23) cb_23.Checked = true;
                else if (l == 0) cb_24.Checked = true;
            }
        }
    }
}
